package com.lijinjiang.reflect05_genericity;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName ReflectDemo
 * @Description TODO
 * @Author Li
 * @Date 2022/9/20 22:08
 * @ModifyDate 2022/9/20 22:08
 * @Version 1.0
 */
public class ReflectDemo {
    public static void main(String[] args) throws Exception {
        List<String> list01 = new ArrayList<>();
        List<Integer> list02 = new ArrayList<>();

        System.out.println(list01.getClass());
        System.out.println(list02.getClass());

        System.out.println(list01.getClass() == list02.getClass()); // ArrayList.class

        System.out.println("==============================");

        List<Integer> list03 = new ArrayList<>();
        list03.add(100);
        list03.add(200);
        // list03.add("三百");
        // 1.获取class对象
        Class c = list03.getClass();
        // 2.获取指定method
        Method method = c.getMethod("add",Object.class);
        // 3.运行该方法
        boolean b = (boolean) method.invoke(list03, "三百");
        System.out.println(b);
        System.out.println(list03);

        System.out.println("==============================");

        List list04 = list03;
        list04.add("四百");
        list04.add(true);
        System.out.println(list03);
    }
}
